const { no, ok, ipv6ToV4, getClientIp } = require('../../utils/utlis');
const visitorService = require('../../services/admin/visitorService');
const JWT = require('../../utils/jwt');
module.exports = {
	add: async (req, res, next) => {
		try {
			let token = JWT.decrypt(req.headers.token);
			let { id: userId } = token;
			let ip = getClientIp(req);
			await visitorService.add(ip, userId);
			res.send(ok('访客添加成功'));
		} catch (error) {
			res.send(no(error));
		}
	},
	list: async (req, res, next) => {
		try {
			let { pageNum, pageSize, keywords, type } = req.body;

			let obj = await visitorService.list(pageNum, pageSize, keywords, type);
			res.send(ok(obj));
		} catch (error) {
			res.send(no(error));
		}
	},
	del: async (req, res, next) => {
		try {
			let { ids } = req.body;

			await visitorService.del(ids);
			res.send(ok());
		} catch (error) {
			res.send(no(error));
		}
	},
};
